﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using com.Bliss.Services;
using com.Bliss;

public partial class Controls_UserFriends : UserControlBase
{
    DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    public int ProfileUserID
    {
        get
        {
            int profileUserID = 0;
            if (Request.QueryString["Id"] == null)
            {
                profileUserID = UserID.Value;
            }
            else
            {
                profileUserID = int.Parse(Request.QueryString["Id"].ToString());
            }
            return profileUserID;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GetUserFriends(ProfileUserID, CompanyID.Value);
        }
    }

    public void GetUserFriends(int userId,int companyId)
    {
        IUserService service = new UserService();
        var res = service.GetFriends(userId, companyId);
        List<com.Bliss.User> lstFriend = res.DataCollection.ToList();
        FreindList.DataSource = lstFriend;
        FreindList.DataBind();

        //string getFriendQuery = "Select * FROM [Users] where Id IN (SELECT MyId as Id FROM Friends WHERE FriendId='" + Id + "' AND FriendStatus=1 UNION SELECT FriendId as Id FROM Friends WHERE MyId='" + Id + "' AND FriendStatus=1) ";
        //dt = dbClass.ConnectDataBaseReturnDT(getFriendQuery);
        //if (dt.Rows.Count > 0)
        //{
        //    FreindList.DataSource = dt;
        //    FreindList.DataBind();
        //}
    }

    public string getHREF(object sURL)
    {
        User dRView = (User)sURL;
        string Id = dRView.ID.ToString();
        if (UserID.Value.ToString() == Id)
        {
            return ResolveUrl("~/UserDetails.aspx");
        }
        else
        {
            return ResolveUrl("~/UserDetails.aspx?Id=" + Id);
        }

    }
    public string getHREFSendMessage(object sURL)
    {
        User dRView = (User)sURL;
        string Id = dRView.ID.ToString();
        if (UserID.Value.ToString() == Id)
        {
            return "#";
        }
        else
        {
            return ResolveUrl("~/SendMessage.aspx?ToId=" + Id);
        }

    }

    public bool getSendMessageVisible(object sURL)
    {
        User dRView = (User)sURL;
        string Id = dRView.ID.ToString();
        if (UserID.Value.ToString()==Id)
        {
            return false;
        }
        else
        {
            return true;
        }

    }
    public string getSRC(object imgSRC)
    {
        User dRView = (User)imgSRC;
        string ImageName = dRView.ImageName;
        if (ImageName == "NoImage")
        {
            return ResolveUrl(@"~/UserImage/image_missing.jpg");
        }
        else
        {
            return ResolveUrl("~/UserImage/" + dRView.ImageName);
        }
    }
    public string getName(object nameSRC)
    {
        User dRView = (User)nameSRC;
        return dRView.Name;
    }
}
